import 'package:flutter/material.dart';
import 'package:talker/talker.dart';
import 'package:talker_flutter/talker_flutter.dart';
import 'package:win32_registry/win32_registry.dart';

final talker = TalkerFlutter.init();

class TalkerPage extends StatefulWidget {
  const TalkerPage({super.key});

  @override
  State<TalkerPage> createState() => _TalkerPageState();
}

class _TalkerPageState extends State<TalkerPage> {
  var macs = "";
  late int i = getValue();

  int getValue() {
    talker.info("getValue");
    return 1;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("TalkerPage"),
        ),
        body: Row(
          children: [
            Expanded(
                child: Column(
              children: [
                FilledButton(
                    onPressed: () {
                      getRememberPCData();
                      talker.info("i:$i");
                    },
                    child: const Text("获取注册表数据")),
                Text("注册表数据:$macs")
              ],
            )),
            Expanded(child: TalkerScreen(talker: talker))
          ],
        ));
  }

  static const _sOneLeapRegistryPath = r'SOFTWARE\TecnoPcManager';
  static const _sPhoneRememberListRegistryKey = "Phone_Accept_Refuse_Remember";

  //获取已经记住当前电脑的手机列表
  String? getRememberPCData() {
    try {
      final key = Registry.openPath(RegistryHive.currentUser,
          path: _sOneLeapRegistryPath,
          desiredAccessRights: AccessRights.readOnly);
      String? data = key.getValueAsString(_sPhoneRememberListRegistryKey);
      talker.info("getRememberPCList $data");
      setState(() {
        macs = data ?? "";
        talker.info("macs $macs");
      });
      return data;
    } catch (e) {
      talker.error("getRememberPCList exception $e");
      return null;
    }
  }
}


class ttt extends StatefulWidget {
  const ttt({super.key});

  @override
  State<ttt> createState() => _tttState();
}

class _tttState extends State<ttt> {
  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}
